package com.theyeasy.dvmini.pc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.theyeasy.dvmini.model.Vanker;
import com.theyeasy.dvmini.service.VankerService;
import com.theyeasy.dvmini.vo.Vo_msg;

@Controller
@RequestMapping("/vanker")
public class VankerController extends BaseController{
	@Autowired
	VankerService vankerService;
	
	@RequestMapping("/vankerIndex")
	public ModelAndView listView(){
		ModelAndView mv = new ModelAndView("/pc/vanker/vanker");
		 
		return mv;
	}
	
	@RequestMapping("/getList")
	public @ResponseBody Vo_msg getList(Integer page){
		return new Vo_msg(0, vankerService.getList(page));
	}
	
	//添加
    @RequestMapping(value = "/addvanker")
    @ResponseBody
    public Object addvanker(String name,String phone) {
        String result=vankerService.addVanker(name, phone);
        if(result.equals("ok")){
            return new Vo_msg(0,"添加成功");
        }else{
            return new Vo_msg(-1,result);
        }
       
    }
    
    //修改
    @RequestMapping(value = "/updatevanker")
    @ResponseBody
    public Object updatevanker(Integer id,String name,String phone,Boolean isvalid) {
        String result=vankerService.updateVanker(id,name, phone, isvalid);
        if(result.equals("ok")){
            return new Vo_msg(0,"修改成功");
        }else{
            return new Vo_msg(-1,result);
        }
     
    }
    
    //删除
    @RequestMapping(value = "/deletevanker")
    @ResponseBody
    public Object deletevanker(Integer id) {
        String result=vankerService.deleteVanker(id);
        if(result.equals("ok")){
            return new Vo_msg(0,"删除成功");
        }else{
            return new Vo_msg(-1,result);
        }
    }
    
    //删除
    @RequestMapping(value = "/getVanker")
    @ResponseBody
    public Object getVanker(Integer id) {
        Vanker vanker=vankerService.getVanker(id);
        if(vanker!=null){
            return new Vo_msg(0,vanker);
        }else{
            return new Vo_msg(-1,"获取失败，数据为空");
        }
    }
    
	
}
